package Concurrency2.Chapter01_Base;

import java.util.concurrent.CountDownLatch;
import java.util.concurrent.TimeUnit;

/**
 * 测试线程的状态
 */
public class T17_ThreadState {
    public static void main(String[] args) throws InterruptedException {
        Object lock = new Object();
        Thread tDemo = new Thread(() -> {
            synchronized (lock) {
                try {
                    lock.wait();
                } catch (InterruptedException e) {
                    throw new RuntimeException(e);
                }
                System.out.println("线程暂停执行...");
            }
        }, "ThreadState");
        tDemo.start();
        TimeUnit.SECONDS.sleep(1);
        System.out.println("唤醒前: " + tDemo.getState());
        //唤醒waiting状态的线程, 但是不释放锁
        synchronized (lock) {
            lock.notify();
            System.out.println("唤醒后: " + tDemo.getState());
            TimeUnit.SECONDS.sleep(1);
        }
        TimeUnit.SECONDS.sleep(1);
        System.out.println("释放锁后: " + tDemo.getState());

    }
}
